﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace DYSales
{
    public partial class Lock_Win : ChildWindow
    {
        public Lock_Win()
        {
            InitializeComponent();
            tb_pwd.AddHandler(KeyDownEvent, new KeyEventHandler(tb_pwd_KeyDown), true);
        }

        void tb_pwd_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                OKButton_Click(null, null);
            }
        }

        protected override void OnOpened()
        {
            base.OnOpened();
            tb_pwd.Focus();
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            dm.getDS().CheckPwd(WebContext.Current.User.Name, tb_pwd.Password, lo =>
            {
                if (!lo.HasError && lo.Value)
                {
                    this.DialogResult = true;
                }
                else
                {
                    tbk_msg.Text = "用户密码错误";
                }
            }, null);

        }
    }
}

